<?php

	class EventItemUserDataAccessMySQL implements iEventItemUserDataAccess {
		
		public function buildObject($result) {
			
			$eventItemUser = new EventItemUser();
			
			$eventUser = new EventUser();
			
			$eventUser->setIsUserConfirmed($result->isConfirmed);
			$eventUser->setIsUserManager($result->isManager);
			$eventUser->setUserRegistrationCode($result->registrationCode);
			
			$user = new User();
			$user->setUserId($result->userId);
			$user->setEmail($result->email);
			$user->setName($result->name);
			
			$eventUser->setUser($user);
			
			$eventItemUser->setEventUser($eventUser);
			$eventItemUser->setIsUserSpeaker($result->isSpeaker);
			
			return $eventItemUser;
		}
		
		public function selectEventItemAttendant($eventItem, $dataBaseConnection) {
			$resultArray = array();
			
			$parameters["EVENTITEMID"] = $eventItem->getEventItemId();
			
			$query = buildQuery("querySelectEventItemAttendant", $parameters);
			if (!is_bool($query)) {
				if ($result = $dataBaseConnection->query($query)) {
					while($row = mysql_fetch_object($result)) {
						array_push($resultArray, $this->buildObject($row));	
					}
					return $resultArray;	
				}
				else {
					return NULL;
				}
			} else {
				return NULL;
			}
		}
		
		public function deleteEventItemAttendant($eventItem, $dataBaseConnection) {
			
			$resultArray = array();
			
			if ($eventItem->getEventItemId() != null){
				$parameters["EVENTITEMID"] = $eventItem->getEventItemId();
			}else {
				$parameters["EVENTITEMID"] = "NULL";
			}
			
			if ($eventItem->getEventItemUser()->getEventUser()->getUserRegistrationCode() != null){
				$parameters["REGISTRATIONCODE"] = $eventItem->getEventItemUser()->getEventUser()->getUserRegistrationCode();
			}else {
				$parameters["REGISTRATIONCODE"] = "NULL";
			}
					
			$query = buildQuery("queryDeleteEventItemAttendant", $parameters);
			if (!is_bool($query)) {
				$result = $dataBaseConnection->query($query);
				
				return $result;
			} else {
				return false;
			}
		}
		
	}

?>